package com.ljw.spring.annotation.handler;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @FileName MyBeanPostProcessor
 * @Description TODO  bean的后置处理器（bean初始化方法执行前后）
 * @Author ljw
 * @Date 2021/2/2 14:57
 * @Version 1.0
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

    //所有的bean在初始化前都会执行方法postProcessBeforeInitialization(...)
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("实例"+beanName+"在初始化方法执行之前先执行方法postProcessBeforeInitialization(..)====》"+bean);
        return bean;
    }


    //所有的bean在初始化后都会执行方法postProcessAfterInitialization(...)
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("实例"+beanName+"在初始化方法执行之后先执行方法postProcessBeforeInitialization(..)====》"+bean);
        return bean;
    }
}
